Programmer's Highway

VB.NET Tips and simple code

I'm very sorry for machine translation in English.

VB.NET IPC InterProcess Communication

InterProcess Communication is a mechanism for exchanging information between between several programs.
Because there is a function of the interprocess communication in .NET Framework, and interprocess communication can easily use it.

The communication method can be selected from a different communication system 3 TCP, HTTP, and IPC.
If you want to communicate between processes on the same machine, we use the IPC channel.

This sample code was referring to the pages of MSDN.
http://msdn.microsoft.com/library/en-us/system.runtime.remoting.channels.ipc.ipcchannel.aspx

IPC Server

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
 
Namespace IpcSample
    Class IpcServer
    
        Public Property RemoteObject() As IpcRemoteObject
    
        Public Sub New()
            ' Create the server channel.
            Dim channel As New IpcServerChannel("ipcSample")
    
            ' Register the server channel.
            ChannelServices.RegisterChannel(channel, True)
    
            ' Create an instance of the remote object.
            RemoteObject = New IpcRemoteObject()
            RemotingServices.Marshal(RemoteObject, "test"GetType(IpcRemoteObject))
        End Sub
    End Class
End Namespace

Please add a "System.Runtime.Remoting" in reference to the project configuration.

IPC Client

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
Imports System.Runtime.Remoting.Channels.Ipc
 
Namespace IpcSample
    Class IpcClient
    
        Public Property RemoteObject() As IpcRemoteObject
    
        Public Sub New()
            ' Create the channel.
            Dim channel As New IpcClientChannel()
    
            ' Register the channel.
            ChannelServices.RegisterChannel(channel, True)
    
            ' Get an instance of the remote object.
            RemoteObject = TryCast(Activator.GetObject(GetType(IpcRemoteObject), "ipc://ipcSample/test"), IpcRemoteObject)
        End Sub
    End Class
End Namespace

Please add a "System.Runtime.Remoting" in reference to the project configuration.

Remote Object

Namespace IpcSample
    Public Class IpcRemoteObject
        Inherits MarshalByRefObject
    
        Public Property Counter() As Integer
    
    End Class
End Namespace

Creates an instance of a server-side program IpcServer to generate a client-side program IpcClient.
While running in separate processes, the properties of each class RemoteObject become such images are sharing the same instance.
Also you can client side is able to generate multiple share a RemoteObject in one-to-many.

Now that it is easier, you may experience problems under is generated in these samples. Also, check the page below.

Visual Studio 2010 .NET Framework 4